/**
 * Copyright 2017 orivil Authors. All rights reserved.
 * Use of this source code is governed by a MIT-style
 * license that can be found at https://mit-license.org.
 */

package swagger

type Properties map[string]*Property

type Property struct {
	// Refer to a model if type is "object"
	Ref string `json:"$ref,omitempty"`

	// Required.
	// The type of the property.
	Type string `json:"type"`

	// The extending format for the previously mentioned type.
	// See Data Type Formats(http://swagger.io/specification/#dataTypeFormat) for further details.
	Format string `json:"format,omitempty"`

	// An example value for this property.
	Example interface{} `json:"example,omitempty"`

	// Adds Additional metadata to describe the XML representation format of this property.
	Xml *Xml `json:"xml,omitempty"`

	// Required if type is "array". Describes the type of items in the array.
	Items *Items `json:"items,omitempty"`

	// Declares the default value of the property that the server will use if none is provided.
	// (Note: "default" has no meaning for required items.)
	// See https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-6.2.
	// Unlike JSON Schema this value MUST conform to the defined type for the data type.
	Default interface{} `json:"default,omitempty"`

	// https://tools.ietf.org/html/draft-fge-json-schema-validation-00#section-5.5.1.
	//Enum []string `json:"enum,omitempty"`

	// A brief description of the parameter. This could contain examples of use.
	// GFM syntax(https://guides.github.com/features/mastering-markdown/#GitHub-flavored-markdown)
	// can be used for rich text representation.
	Description string `json:"description,omitempty"`

	*Validation
}

func (p *Property) setDataType(typ, format string, items *Items) {
	p.Type = typ
	p.Format = format
	p.Items = items
}